﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CourseSystem.Core.Entities.ExaminationInfo>" %>
<%@ Import Namespace="Chowpoo.Util" %>
<%@ Import Namespace="CourseSystem.Common.Helpers" %>
<%
    var examInfo = Model;
    if (examInfo == null)
    { %>
空.
<%}
    else if (examInfo.Status != 1)
    { %>
空.
<%}
    else
    {
        //如果是考试
        if (examInfo.Type == 4)
        {
            var reExam = ViewData["reExam"].CheckInt(0);
            if (examInfo.Status == 0)
            {
                Response.Write("该考试未发布!");
                return;
            }
            var sumInfo =
                examInfo.ExamSummaryInfo.FirstOrDefault(
                    o => o.Uid == UserHelper.LoginUser.Id);
            if (reExam == 0 && sumInfo != null && sumInfo.IsCommit)
            {
                Response.Write("您已成功提交该考试!请等待批改!");
                return;
            }
        }
        var currentTitleId = 1;
        var needWash = examInfo.QuestionType == 1 || examInfo.QuestionType == 3;
        var needAnsWash = examInfo.QuestionType == 2 || examInfo.QuestionType == 3;
        var stuKeyList = examInfo.ExamAnswerInfo.Where(o => o.Uid == UserHelper.LoginUser.Id).ToList();
        var type0Model =
            examInfo.ExaminationItemInfo.Where(o => o.QuestionLibInfo.Type == 0).ToList();
        var type0Count = type0Model.Count;
        var type1Model =
            examInfo.ExaminationItemInfo.Where(o => o.QuestionLibInfo.Type == 1).ToList();
        var type1Count = type1Model.Count;
        var type2Model =
           examInfo.ExaminationItemInfo.Where(o => o.QuestionLibInfo.Type == 2).ToList();
        var type2Count = type2Model.Count;
        var type3Model =
           examInfo.ExaminationItemInfo.Where(o => o.QuestionLibInfo.Type == 3).ToList();
        var type3Count = type3Model.Count;
        var type4Model =
           examInfo.ExaminationItemInfo.Where(o => o.QuestionLibInfo.Type == 4).ToList();
        var type4Count = type4Model.Count; 
%>
<%using (Html.BeginForm("ExamSave", "ExamLib", new { examInfo.Id }, FormMethod.Post, new { id = "examForm", name = "examForm" }))
  { %>
<% if (type0Count != 0)
   {
       var i = 1; %>
<table width="748" height="30" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30" class="style31">
            <%= NumHelper.GetChineseNum(currentTitleId++) %>、<strong>单项选择题</strong>
        </td>
    </tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <div align="left" class="style1">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <%
       var type0OrderList = ExamLibHelper.GetOrderList(examInfo.Id, 0, UserHelper.LoginUser.Id,
                                                       type0Model.Count, needWash);

       for (int ii = 0; ii < type0OrderList.Count; ii++)
       {
           var item = type0Model[type0OrderList[ii]];
           var keyInfo =
                stuKeyList.FirstOrDefault(o => o.Qid == item.Qid);%>
                    <tr>
                        <td class="style48">
                            <span class="style53">[<%=ExamLibHelper.GetScoreTran(item.QuestionLibInfo.Score, Model.Score)%>分]</span><%= i++ %>．<%= item.QuestionLibInfo.Title %>
                        </td>
                    </tr>
                    <%
           var type0AnsOrder = ExamLibHelper.GetRanList(item.QuestionLibInfo.RadioChoicesInfo.Count, needAnsWash);

           for (int j = 0; j < type0AnsOrder.Count; j++)
           {
               var info = item.QuestionLibInfo.RadioChoicesInfo[type0AnsOrder[j]];
                    %>
                    <tr>
                        <td class="style48">
                            <%=
                                                           Html.RadioButton("radio" + item.QuestionLibInfo.Id, info.Id,
                                                                            keyInfo != null &&
                                                                            keyInfo.AnswerId == info.Id,
                                                                            new {id = "radio" + info.Id}) %>
                            <%-- <input type="radio" name="radio<%=item.QuestionLibInfo.RadioChoicesInfo[j].Id %>" value="<%=item.QuestionLibInfo.RadioChoicesInfo[j] %>"/>--%>
                            <label for="radio<%= info.Id %>">
                                <%= RadioChoicesHelper.GetChoiceLetter(j) %>.<%= info.Title %></label>
                        </td>
                    </tr>
                    <% } %>
                    <% } %>
                </table>
            </div>
        </td>
    </tr>
</table>
<% } %>
<% if (type1Count != 0)
   {
       var i = 1; %>
<table width="748" height="30" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30" class="style31">
            <%= NumHelper.GetChineseNum(currentTitleId++) %>、<strong>多项选择题</strong>
        </td>
    </tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <div align="left" class="style1">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <% var type1OrderList = ExamLibHelper.GetOrderList(examInfo.Id, 1, UserHelper.LoginUser.Id,
                                                       type1Model.Count, needWash);

                       for (int ii = 0; ii < type1OrderList.Count; ii++)
                       {
                           var item = type1Model[type1OrderList[ii]];
                           var keyInfo =
                               stuKeyList.FirstOrDefault(o => o.Qid == item.Qid);%>
                    <tr>
                        <td class="style48">
                            <span class="style53">[<%=ExamLibHelper.GetScoreTran(item.QuestionLibInfo.Score, Model.Score)%>分]</span><%= i++ %>．<%= item.QuestionLibInfo.Title %>
                        </td>
                    </tr>
                    <%
                           var type1AnsOrder = ExamLibHelper.GetRanList(item.QuestionLibInfo.RadioChoicesInfo.Count, needAnsWash);
                           for (int j = 0; j < type1AnsOrder.Count; j++)
                           {
                               var info = item.QuestionLibInfo.RadioChoicesInfo[type1AnsOrder[j]];
                        
                    %>
                    <tr>
                        <td class="style48">
                            <%= Html.CheckBox("check" + info.Id,
                                                                                        keyInfo != null &&
                                                                                        (","+keyInfo.Answer+",").Contains(","+info.Id+","),
                                                                                        new {id = "check" + info.Id}) %>
                            <%-- <input type="radio" name="radio<%=item.QuestionLibInfo.RadioChoicesInfo[j].Id %>" value="<%=item.QuestionLibInfo.RadioChoicesInfo[j] %>"/>--%>
                            <label for="check<%= info.Id %>">
                                <%= RadioChoicesHelper.GetChoiceLetter(j) %>.<%= info.Title %></label>
                        </td>
                    </tr>
                    <% } %>
                    <% } %>
                </table>
            </div>
        </td>
    </tr>
</table>
<% } %>
<% if (type2Count != 0)
   {
       var i = 1; %>
<table width="748" height="30" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30" class="style31">
            <%= NumHelper.GetChineseNum(currentTitleId++) %>、<strong>判断题</strong>
        </td>
    </tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <div align="left" class="style1">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <%  var type2OrderList = ExamLibHelper.GetOrderList(examInfo.Id, 2, UserHelper.LoginUser.Id,
                                                       type2Model.Count, needWash);

                        for (int ii = 0; ii < type2OrderList.Count; ii++)
                        {
                            var item = type2Model[type2OrderList[ii]];
                            var keyInfo =
                                 stuKeyList.FirstOrDefault(o => o.Qid == item.Qid);%>
                    <tr>
                        <td class="style48">
                            <span class="style53">[<%=ExamLibHelper.GetScoreTran(item.QuestionLibInfo.Score, Model.Score)%>分]</span><%= i++ %>．<%= item.QuestionLibInfo.Title %>
                        </td>
                    </tr>
                    <tr>
                        <td class="style48">
                            该命题是否正确?<%= Html.CheckBox("checkpan" + item.QuestionLibInfo.Id,keyInfo != null &&string.IsNullOrEmpty(keyInfo.Answer))%>
                        </td>
                    </tr>
                    <% } %>
                </table>
            </div>
        </td>
    </tr>
</table>
<% } %>
<% if (type3Count != 0)
   {
       var i = 1; %>
<table width="748" height="30" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30" class="style31">
            <%= NumHelper.GetChineseNum(currentTitleId++) %>、<strong>论述题</strong>
        </td>
    </tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <div align="left" class="style1">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <%  var type3OrderList = ExamLibHelper.GetOrderList(examInfo.Id, 3, UserHelper.LoginUser.Id,
                                                       type3Model.Count, needWash);

                        for (int ii = 0; ii < type3OrderList.Count; ii++)
                        {
                            var item = type3Model[type3OrderList[ii]];
                            var keyInfo =
                                stuKeyList.FirstOrDefault(o => o.Qid == item.Qid);%>
                    <tr>
                        <td class="style48">
                            <span class="style53">[<%=ExamLibHelper.GetScoreTran(item.QuestionLibInfo.Score, Model.Score)%>分]</span><%= i++ %>．<%= item.QuestionLibInfo.Title %>
                        </td>
                    </tr>
                    <tr>
                        <td class="style48">
                            <%= Html.TextArea(
                                                                "area" + item.QuestionLibInfo.Id,
                                                                keyInfo == null ? "" : keyInfo.Answer,
                                                                new {@class = "editArea"}) %>
                        </td>
                    </tr>
                    <% } %>
                </table>
            </div>
        </td>
    </tr>
</table>
<% } %>
<% if (type4Count != 0)
   {
       var i = 1; %>
<table width="748" height="30" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30" class="style31">
            <%= NumHelper.GetChineseNum(currentTitleId++) %>、<strong>思考题</strong>
        </td>
    </tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <div align="left" class="style1">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <%  var type4OrderList = ExamLibHelper.GetOrderList(examInfo.Id, 4, UserHelper.LoginUser.Id,
                                                       type4Model.Count, needWash);

                        for (int ii = 0; ii < type4OrderList.Count; ii++)
                        {
                            var item = type4Model[type4OrderList[ii]];
                            var keyInfo =
                                stuKeyList.FirstOrDefault(o => o.Qid == item.Qid);%>
                    <tr>
                        <td class="style48">
                            <span class="style53">[<%=ExamLibHelper.GetScoreTran(item.QuestionLibInfo.Score, Model.Score)%>分]</span><%= i++ %>．<%= item.QuestionLibInfo.Title %>
                        </td>
                    </tr>
                    <tr>
                        <td class="style48">
                            <%= Html.TextArea(
                                                                "area" + item.QuestionLibInfo.Id,
                                                                keyInfo == null ? "" : keyInfo.Answer,
                                                                new {@class = "editArea"}) %>
                        </td>
                    </tr>
                    <% } %>
                </table>
            </div>
        </td>
    </tr>
</table>
<% } %>
<table width="650" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td align="center">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="style1" height="20" width="50">
                        <input type="submit" id="saveSubmit" name="Save" value="保存" />
                    </td>
                    <td>
                        <span class="style48">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                    </td>
                    <td class="style1">
                        <input type="submit" id="submitSubmit" name="Submit" value="提交" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<% }
    }%>